package com.atguigu.serviceBase.component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Aug28-tlsjn
 * @date 2020-06-30 Tuesday 12:08
 */
@Component
public class MyMetaObjetHandler implements MetaObjectHandler {

    private String creatTime =  "gmtCreate";

    private String modifiedTime = "gmtModified";

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName(creatTime, new Date(), metaObject);
        this.setFieldValByName(modifiedTime, new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName(modifiedTime, new Date(), metaObject);
    }
}
